import store from '@/store.js'
const STORAGE_KEY = 'local-storage-'
export default {
  fetch: function (key) {
    return JSON.parse(window.localStorage.getItem(
      STORAGE_KEY+key) || '[]')
  },
  save: function (key,items) {
    window.localStorage.setItem(STORAGE_KEY+key, JSON.stringify(items))
  },
  getSession:function(key){
    return window.sessionStorage.getItem(key)||''
  },
  setSession:function(key,value){
    window.sessionStorage.setItem(key,value)
  },
  initUserInfo:function () {
    if(!store.state.token){
      let userInfo=this.getSession('login_userinfo')
      if(userInfo){
        userInfo=JSON.parse(userInfo)
        store.commit('changeUserInfo',userInfo)
      }
    }
  }
}
